package com.tentact.coolmeetingtest.service;

import com.tentact.coolmeetingtest.dao.RoomDao;
import com.tentact.coolmeetingtest.support.RetMsg;
import com.tentact.coolmeetingtest.vo.Room;

import java.util.List;

/**
 * @author 星环
 * @date 2023/1/30 9:58:46
 * @description
 */
public class RoomService {
    RoomDao roomDao = new RoomDao();
    public RetMsg addRoom(Room room){
        if(room.getState() <= 0 || room.getPersonCount() <= 0){
            return RetMsg.msg(-1,"容纳人数请输入正整数");
        }
        int i = roomDao.addRoom(room);
        if(i == 1){
            return RetMsg.msg(i,"添加成功");
        }else {
            return RetMsg.msg(i,"添加失败");
        }
    }

    public List<Room> getAll(){
        return roomDao.selectAll();
    }

    public Room getDetailByRoomno(int roomno){
        return roomDao.selectByNo(roomno);
    }

    public RetMsg changeRoomById(Room room) {
        if(room.getPersonCount() < 1){
            return RetMsg.msg(-1,"人数应该是正整数！");
        }
        int code = roomDao.updateRoomByRoomno(room);
        if(code == 1){
            return RetMsg.msg(code,"修改成功");
        }else {
            return RetMsg.msg(code,"修改失败");
        }
    }
}
